home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Java for 3D & VRML Worlds
/
Java for 3d and VRML Worlds.iso
/
world
/
shadow
/
shadow1.java
< prev
next >
Wrap
Text File
|
1996-10-17
|
4KB
|
243 lines
// "Motion Shadow Effect"
// created by ask@krc.sony.co.jp (Masamichi zzzcat Asukai)
//
// Copyright(C) 1996 Sony Corporation. All rights reserved.
//
import vrml.*;
import vrml.node.*;
import vrml.field.*;
public class shadow1 extends Script {
private Node light;
private Node object;
private boolean shadow_length;
private boolean shadow_depth;
private SFVec3f lightTranslation;
private SFVec3f objectTranslation;
private SFVec3f objectScale;
private SFRotation shadowRotation;
private SFVec3f shadowScale;
private SFFloat shadowTransparency;
private float[] l_trans = new float[3];
private float[] o_trans = new float[3];
private float[] o_scale = new float[3];
private float[] s_rot = {0.0f, 1.0f, 0.0f, 0.0f};
private float[] s_scale = {1.0f, 1.0f, 1.0f};
private float s_transparency;
private float[] vec = new float[3];
private float d;
public void initialize() {
// get field values of script node
light = (Node)((SFNode)getField("light")).getValue();
object = (Node)((SFNode)getField("object")).getValue();
shadow_length =
(boolean)((SFBool)getField("shadow_length")).getValue();
shadow_depth =
(boolean)((SFBool)getField("shadow_length_and_depth")).getValue();
// get exposed fields
lightTranslation = (SFVec3f)light.getExposedField("translation");
objectTranslation = (SFVec3f)object.getExposedField("translation");
objectScale = (SFVec3f)object.getExposedField("scale");
shadowRotation = (SFRotation)object.getExposedField("shadow_rotation");
shadowScale = (SFVec3f)object.getExposedField("shadow_scale");
shadowTransparency = (SFFloat)object.getExposedField("shadow_transparency");
}
public void processEvent(Event e) {
if (e.getName().equals("interval")) {
lightTranslation.getValue(l_trans);
objectTranslation.getValue(o_trans);
objectScale.getValue(o_scale);
////////////////////
// SHADOW ROTATION
////////////////////
// normalized light vector on X-Z plane
vec[0] = o_trans[0] - l_trans[0];
vec[2] = o_trans[2] - l_trans[2];
d = (float)java.lang.Math.sqrt(vec[0]*vec[0] + vec[2]*vec[2]);
vec[0] /= d;
vec[2] /= d;
// rotation of shadow
if (vec[0] < 0.0) {
s_rot[3] = (float)java.lang.Math.acos(-vec[2]);
} else {
s_rot[3] = -(float)java.lang.Math.acos(-vec[2]);
}
// set rotation of shadow
shadowRotation.setValue(s_rot);
////////////////////
// SHADOW LENGTH
////////////////////
if (true == shadow_length || true == shadow_depth) {
// whether light height is higher than top of object
if (l_trans[1] < o_scale[1]) {
s_scale[2] = 0.0f;
} else {
s_scale[2] = d / (l_trans[1] - o_scale[1]);
}
}
if (true == shadow_length) {
// set length of shadow
shadowScale.setValue(s_scale);
}
////////////////////
// SHADOW DEPTH
////////////////////
if (true == shadow_depth) {
if (s_scale[2] < 1.0f) {
s_transparency = 0.0f;
} else {
s_transparency = 1.0f / s_scale[2];
// s_transparency = 1.0f / (s_scale[2] * s_scale[2]);
s_transparency = 1.0f - s_transparency;
}
// set depth of shadow
shadowTransparency.setValue(s_transparency);
}
}
}
}